package com.auxgroup.hr.front.service.hireperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.dao.domain.PsCHirePrimaryClass;
import com.auxgroup.hr.front.dao.domain.PsCHireSiTbl;
import com.auxgroup.hr.front.dao.repository.PsCHireSiTblRepository;
import com.auxgroup.hr.front.service.hireperson.HireSiService;

/** 
 * @author lvliuhao
 * @version 创建时间：180523 
 * 入职人员社保公积金service
 */
@Service("hireSiService")
public class HireSiServiceImpl implements HireSiService {
	private static final Logger logger = LoggerFactory.getLogger(HireEducatServiceImpl.class);
	
	@Autowired
	private PsCHireSiTblRepository PsCHireSiTblRepository;


	@Override
	public PsCHireSiTbl getHireSi(PsCHirePrimaryClass primaryClass) {
		return PsCHireSiTblRepository.findOne(primaryClass);
	}


	@Override
	public PsCHireSiTbl save(PsCHireSiTbl HireSi) {
		if(HireSi.getcSeqno()==null){
			HireSi.setHrsRowAddOprid(HireSi.getRsHireId());
			HireSi.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		}
		HireSi.setHrsRowUpdOprid(HireSi.getRsHireId());
		HireSi.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(HireSi, ignoreFields);
		return PsCHireSiTblRepository.save(HireSi);
	}


	@Override
	public Boolean delete(PsCHirePrimaryClass primaryClass) {
		try {
			PsCHireSiTblRepository.delete(primaryClass);
		} catch (Exception e) {
			logger.error("delete HireSi error: primaryClass={}",primaryClass,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCHireSiTbl> getAll(String rsHireId) {
		PsCHireSiTbl HireSi = new PsCHireSiTbl();
		HireSi.setRsHireId(rsHireId);
		return PsCHireSiTblRepository.findAll(Example.of(HireSi));
	}


	
	
	
}
